<template>
    <el-dialog
      width="50%"
      title="详情"
      :close-on-click-modal="false"
      :visible.sync="visible">
      <el-form :model="dataForm" ref="dataForm" label-width="100px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="秒杀id" prop="id">
              <el-input readonly v-model="dataForm.id"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="商品名称" prop="productName">
            <el-input readonly v-model="dataForm.productName"></el-input>
          </el-form-item>
        </el-row>  
        <el-form-item label="场次" prop="session">
          <el-col :span="10">
            <el-input readonly v-model="dataForm.startTime" ></el-input>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="10">
            <el-input readonly v-model="dataForm.endTime" ></el-input>
          </el-col>
        </el-form-item>
        <el-row>
          <el-col :span="11">
            <el-form-item label="秒杀商品数量" prop="seckillCount">
              <el-input readonly v-model="dataForm.seckillCount"  label="秒杀商品数量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="最大购买数量" prop="seckillLimit">
              <el-input readonly v-model="dataForm.seckillLimit"  :min="1" :max="dataForm.seckillCount" label="购买数量最大限制"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="秒杀价格" prop="seckillPrice">
              <el-input readonly v-model="dataForm.seckillPrice"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="秒杀状态" prop="seckillStatus">
              <el-input readonly v-model="statusChange"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="visible = false">确定</el-button>
    </span>
    </el-dialog>
  </template>
  
  <script>
  import request from "@/utils/request";
    export default {
      
      data () {
        return {
          visible: false,
          dataForm: {
            id: 0,
            productName: '',
            startTime: '', 
            endTime: '',
            seckillPrice: 0,
            seckillCount: '',
            seckillLimit: '',
            seckillStatus: 0
          },
          statusMap:{
            "0":"未启用",
            "1":"已启用"
          }
        }  
      },
    
      components: {},
      methods: {
        forminit (id) { 
          // this.dataForm.id = id 
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            if (id) {
              request.get(`/seckill/relation/admin/sessionDetails/${id}`).then((response) => {  
                if (response.data && response.data.code === 200) { 
                  this.dataForm.id = id 
                  this.dataForm.productName = response.data.relation.productName
                  this.dataForm.startTime = response.data.relation.startTime
                  this.dataForm.endTime = response.data.relation.endTime
                  this.dataForm.seckillPrice = response.data.relation.seckillPrice  
                  this.dataForm.seckillCount = response.data.relation.seckillCount  
                  this.dataForm.seckillLimit = response.data.relation.seckillLimit  
                  this.dataForm.seckillStatus = response.data.relation.seckillStatus  
                } 
              })
            }
          })
        },
      },
      computed: {
        //展示实际状态
        statusChange() {
          return this.statusMap[this.dataForm.seckillStatus] || '空'
        },
      }
    }
  </script>
  